$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    console.log('detail Ready');
    var mstform = $NG.getCmpApi('p_form_tbjdfxpg_m');
    if (page.oType == "add") {
        mstform.getItem('u_basp').setValue('分公司')
    }
    useValuesChange(({ args }) => {
        let u_bdmc = mstform.getItem('u_bdmc').getValue();
        console.log("当前BDMC值:", u_bdmc);
        $NG.execServer("searchNew", { user_bdmc: u_bdmc }, (res2) => {
            if (res2.count === 0) return;
            const xmmsData = JSON.parse(res2.data)[0].extendObjects;
            console.log(xmmsData);

            $NG.updateState((updater) => {
                updater.data.p_form_tbjdfxpg_m.setProps({
                    u_xmmc: xmmsData.project_name,
                    u_ssdw: xmmsData.user_yzdw,
                    // u_ssdw: {
                    //     value: xmmsData.phid_org,
                    //     label: user_xmms_EXName,
                    // }
                });
            });
        });
    }, "p_form_tbjdfxpg_m.u_bdmc");

    useValuesChange(()=>{setUlre()},"p_form_tbjdfxpg_m.u_htje")
    useValuesChange(()=>{setUlre()},"p_form_tbjdfxpg_m.u_cszcb")
    useValuesChange(()=>{setUlre()},"p_form_tbjdfxpg_m.u_yysr")

    // 校验是否亏损
    const ksBtn = ['u_cszcb', 'u_htje']
    ksBtn.forEach(item => {
        useValuesChange(() => {
            const u_cszcb = mstform.getItem("u_cszcb").getValue()
            if ((Number(u_cszcb) || 0) > (Number(mstform.getItem("u_htje").getValue()) || 0)) {
                mstform.getItem("u_sfks").setValue('01')
            } else {
                mstform.getItem("u_sfks").setValue("02")
            }

        }, "p_form_tbjdfxpg_m." + item)
    })

    function setUlre() {
        let u_htje = (Number(mstform.getItem('u_htje').getValue()) || 0);
        let u_cszcb = (Number(mstform.getItem('u_cszcb').getValue()) || 0);
        let u_yysr = (Number(mstform.getItem("u_yysr").getValue()) || 0)
        mstform.getItem('u_lre').setValue(u_htje - u_cszcb)
        mstform.getItem("u_xmlr").setValue(u_yysr - u_cszcb)
    }

}, function () {
    console.log('list Ready');
});